/**
 * blank
 */

define(function (require) {
    var $ = require('jquery');
    var base = require('base');
    var com = require('./common');

    if(localStorage.getItem("lang")){
		var Lang = localStorage.getItem("lang")
	}else{
		var Lang = "zh_CN"
	}
    
    // 中文/英文转换
    let prev_text = next_text = "";
	if(Lang != "zh_CN"){
		$('#detail_text').html("News Information")
		$('#create_time').html("Create Time: ")
		$('#detail_font_size').html("Font Size")
		$('#back').html("back")
		$('#hot_news').html("Hot News")

        prev_text = "Prev Page";
        next_text = "Next Page";
	}else{
        prev_text = "上一篇";
        next_text = "下一篇";
    }

    var a=location.search;
    var b=a.substr(1);
    console.log('b:',b)
    let data = b.split("=");
    console.log(data)

    // 文章详情
	$.ajax(seajs.ajaxroot + "getDetail",{
		type:'post',
		data:{id:data[1]},
		headers:{
			'locale-language':Lang
		},
		success:function(res){	            
            let data = res.data;
            $("#date").html(data.article.date)
            $("#article_title").html(data.article.title)
            $("#article_info").html( data.article.content);

            

            let prev = '<a href="/detail.html?id='+data.prev_article.id+'"><div class="tit">'+prev_text+'</div>';
            prev += '<span class="d"><i class="iconfont" data-code="xe64d;"></i id="prev_article_date">'+data.prev_article.date+'</span>';
            prev += '<div class="t" id="prev_article_title">'+data.prev_article.title+'</div></a>';
            $('#prev').html(prev);
            
            let next = '<a href="/detail.html?id="'+data.next_article.id+'><div class="tit">'+next_text+'</div>';
            next += '<span class="d"><i class="iconfont" data-code="xe64d;"></i>'+data.next_article.date+'</span>';
            next += '<div class="t">'+data.next_article.title+'</div></a>';
            $('#next').html(next);
            

		},
		error:function(err){
			console.log("error:", err)
		}

	});


    // 热门新闻
	$.ajax(seajs.ajaxroot + "getHotArticle",{
		type:'post',
		headers:{
			'locale-language':Lang
		},
		success:function(res){	
            
            let hot = '';
            res.data.forEach(item=>{
                hot += '<li><a href="/detail.html?id="'+item.id+'>';
                hot += '<div class="t el">'+item.title+'</div>';
                hot += '<span class="d">'+item.date+'</span></a></li>';                  
            })
            $("#hotArticle").html(hot);

		}

	});


});